package top.infopub.mgr.fia.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.google.common.collect.Maps;

import top.infopub.generic.GenericDao;
import top.infopub.generic.GenericServiceImpl;
import top.infopub.mgr.fia.dao.FundsHandDetailDao;
import top.infopub.mgr.fia.domain.FundsHandDetailDomain;
import top.infopub.model.fia.FundsHandDetail;
import top.infopub.mgr.fia.service.FundsHandDetailService;
import top.infopub.mgr.util.DateUtils;

@Service
public class FundsHandDetailServiceImpl extends GenericServiceImpl<FundsHandDetail, String> implements
		FundsHandDetailService {

	@Autowired
	private FundsHandDetailDao fundsHandDetailDao;
	
	@Override
	public GenericDao<FundsHandDetail, String> getDao() {
		return fundsHandDetailDao;
	}

    @Override
    public Page<FundsHandDetailDomain> selectDataByWhere(Date monthStart, Date monthEnd,
                                                         String type, String orgId,
                                                         Page<FundsHandDetailDomain> page) {
        PageHelper.startPage(page.getPageNum(), page.getPageSize());
        Map<String, Object> where = Maps.newHashMap();
        where.put("stsMonthStart", monthStart);
        Date stsMonthEnd = DateUtils.getMonthEnd(monthEnd);
        where.put("stsMonthEnd", stsMonthEnd);      
        where.put("hrOrgBillId", orgId);       
        return (Page<FundsHandDetailDomain>)fundsHandDetailDao.selectDataByWhere(where);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteByFundsHandId(String fundsHandId) {
        
        fundsHandDetailDao.deleteByFundsHandId(fundsHandId);
        
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void addFundsHandDetail(List<FundsHandDetail> fundsHandDetails) {
        
        if(CollectionUtils.isNotEmpty(fundsHandDetails)){
            fundsHandDetailDao.insertByBatch(fundsHandDetails);
        }
        
    }

}